package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.AlertDataPageQueryDto;
import com.zzyl.dto.AlertRuleDto;
import com.zzyl.dto.AlertRulePageQueryDto;
import com.zzyl.entity.AlertRule;
import com.zzyl.service.AlertRuleService;
import com.zzyl.vo.AlertRuleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/alert-rule")
@Api(tags = "报警规则相关接口")
public class AlertRuleController {

    @Autowired
    private AlertRuleService alertRuleService;

    @GetMapping("/read/{id}")
    @ApiOperation("获取单个告警规则")
    public ResponseResult<AlertRule> findById(@PathVariable Long id) {
        return alertRuleService.findById(id);
    }

    @GetMapping("/get-page")
    @ApiOperation("分页获取告警规则")
    public ResponseResult<PageResponse<AlertRuleVo>> getPage(AlertRulePageQueryDto dto) {
        return alertRuleService.getPage(dto);
    }

    @GetMapping
    public List<AlertRule> findAll() {
        return alertRuleService.findAll();
    }

    /**
     * 新增报警规则
     */
    @PostMapping("/create")
    @ApiOperation("新增报警规则")
    public ResponseResult insert(@RequestBody AlertRuleDto alertRuleDto) {
        alertRuleService.insert(alertRuleDto);
        return ResponseResult.success();
    }

    @PutMapping("/update/{id}")
    @ApiOperation("更新报警规则")
    public ResponseResult update(@PathVariable Long id, @RequestBody AlertRule alertRule) {
        alertRule.setId(id);
        alertRuleService.update(alertRule);
        return ResponseResult.success();
    }

    @DeleteMapping("/delete/{id}")
    public ResponseResult delete(@PathVariable Long id) {
        alertRuleService.delete(id);
        return ResponseResult.success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启动禁用告警规则")
    public ResponseResult startOrStop(@PathVariable Integer id, @PathVariable Integer status) {
        alertRuleService.startOrStop(id, status);
        return ResponseResult.success();
    }

}